/*
 * @Description: 增加代码库弹窗组件
 * @Author: Rfan
 * @Date: 2022-01-07 14:54:11
 * @LastEditTime: 2022-02-15 15:43:39
 */

import { Button, Form, Input, Modal, Radio } from 'antd';
import type { ValidateErrorEntity } from 'rc-field-form/lib/interface';
import { useCodeDefContext } from '../contexts/CodeDefContext';

const AddLibDialog = () => {
  const { loading } = useCodeDefContext();
  const [form] = Form.useForm();

  const submitFunc = () => {
    console.log('submit', form);
    form.submit();
  };

  const onFinish = (val: any) => {
    console.log('form finish', val);
  };

  const onFinishFailed = (errorInfo: ValidateErrorEntity) => {
    console.log('Failed:', errorInfo);
  };

  const onCancel = () => {};

  return (
    <Modal
      destroyOnClose
      title="新增代码定义"
      visible={loading}
      onCancel={onCancel}
      footer={[
        <Button key="back" onClick={onCancel}>
          取消
        </Button>,
        <Button key="submit" type="primary" onClick={submitFunc}>
          确定
        </Button>
      ]}
    >
      <Form
        labelCol={{ span: 6 }}
        wrapperCol={{ span: 14 }}
        preserve={false}
        form={form}
        onFinish={onFinish}
        onFinishFailed={onFinishFailed}
      >
        <Form.Item
          name="fondCode"
          label="代码库名称"
          extra="代码库显示名称，不能重复"
          rules={[{ required: true, message: '请填写代码库名称' }]}
        >
          <Input />
        </Form.Item>
        <Form.Item
          name="fondName"
          label="代码库编号"
          extra="代码库标识，不能重复，建议用数据和字母组成"
          rules={[{ required: true, message: '请填写代码库编号' }]}
        >
          <Input allowClear />
        </Form.Item>
        <Form.Item name="type" label="类型">
          <Radio.Group>
            <Radio value="a">item 1</Radio>
            <Radio value="b">item 2</Radio>
            <Radio value="c">item 3</Radio>
          </Radio.Group>
        </Form.Item>
        <Form.Item name="comment" label="备注">
          <Input.TextArea />
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default AddLibDialog;
